<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/mui.picker.min.css" rel="stylesheet">
		<link href="../css/header.css" rel="stylesheet">
	</head>
	<style>
		.input-group{
			float: right;
			border: none;
			padding-right:0;
			color: #999;
		}
		.information{
			height: 3rem;
			line-height: 3rem;
		}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<a id="link_submit_userinfo" class="mui-icon mui-icon-right-nav mui-pull-right" 
				style="color: white;font-size: 14px;line-height: 25px;">修改</a>
			<h1 class="mui-title title-color">个人资料</h1>
		</header>
		<div class="mui-content"> 
		 <ul class="mui-table-view">
		<li class="mui-table-view-cell mui-media">
		    <a id="link_nickname" href="javascript:;">
		        <div class="mui-media-body information">
		            姓名
					<input type="text" id="txt_name" class="mui-input mui-input-clear input-group"  
					style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right" />
		        </div>
		    </a>
		</li>
		<li class="mui-table-view-cell mui-media">
		    <a id="link_nickname" href="javascript:;">
	
		        <div class="mui-media-body information" id="selectSex">
		            性别   
					<input type="text" id="txt_sex" class="mui-input mui-input-clear input-group" 
					style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right" />
		        </div>
		    </a>
		</li>
		<li class="mui-table-view-cell mui-media" id="selectDate">
		        <div class="mui-media-body information">
		            生日
					<input type="text" id="txt_birthday" class="mui-input mui-input-clear input-group" 
					style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right;"/>
		        </div>
		</li>
		<li class="mui-table-view-cell mui-media">
			<div class="mui-media-body information">
		            身高
					<input type="text" id="txt_height" class="mui-input mui-input-clear input-group" 
					style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right"  />
				</div>
		</li>
		<li class="mui-table-view-cell mui-media">
	
		        <div class="mui-media-body information">
		           初始体重
				   <input type="text" id="txt_beginweight" class="mui-input mui-input-clear input-group" 
				   style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right"  />
		        </div>
		    
		</li>
		<li class="mui-table-view-cell mui-media">
		        <div class="mui-media-body information">
		           目标体重
				   <input type="text" id="txt_goalweight" class="mui-input mui-input-clear input-group" 
				   style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right"  />
		        </div>
		   
		</li>
		<li class="mui-table-view-cell mui-media">
		        <div class="mui-media-body information">
		           现在体重
				   <input type="text" id="txt_nowweight" class="mui-input mui-input-clear input-group" 
				   style="border-width: 0;outline: medium; width: 10rem;height: 3rem;text-align:right"  />
		        </div>
		   
		</li>
	</ul>
</div>
		<script src="../js/mui.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.plusReady(function () {
				
			   // 获得当前的webview，刷新当前用户信息
			   var infoWebview = plus.webview.currentWebview();
			   infoWebview.addEventListener("show", function() {
			   	refreshUserInfo();
			   }); 
			   //提交修改申请
			   var link_submit_userinfo = document.getElementById("link_submit_userinfo");
			   link_submit_userinfo.addEventListener("tap",function(){
				   var txt_name = document.getElementById("txt_name").value;
				   var txt_sex = document.getElementById("txt_sex").value;
				   var txt_birthday = document.getElementById("txt_birthday").value;
				   var txt_height = document.getElementById("txt_height").value;
				   var txt_beginweight = document.getElementById("txt_beginweight").value;
				   var txt_goalweight = document.getElementById("txt_goalweight").value;
				   var txt_nowweight = document.getElementById("txt_nowweight").value;
				   var userinfo = app.getRealInfoGlobal();
				   plus.nativeUI.showWaiting("请稍候...");
				   mui.ajax(app.serverUrl+'/user/update/2',{
				   	data:{
						  id:userinfo.id,
						  uid:userinfo.uid,
						  name:txt_name,
						  sex:txt_sex,
						  birthday:txt_birthday,
						  height:txt_height,
						  beginweight:txt_beginweight,
						  goalweight:txt_goalweight,
						  nowweight:txt_nowweight
				   	},
				   	dataType:'json',//服务器返回json格式数据
				   	type:'post',//HTTP请求类型
				   	timeout:10000,//超时时间设置为10秒；
				   	success:function(data){
				   		plus.nativeUI.closeWaiting();
						app.setRealInfoGlobal(data.data);
						console.log(JSON.stringify(data.data));
				   	},
				   	error:function(xhr,type,errorThrown){
				   		
				   	}
				   });
			   });
			   var selectDate = document.getElementById("selectDate");
			   selectDate.addEventListener("tap",function(){
				   option = {"type" : "date","beginYear" : "1949","endYear":"2019"};
				   var picker = new mui.DtPicker(option);
				   picker.show(function(rs){
					   console.log(rs.text);
					   txt_birthday.value = rs.text;
				   });
			   },false);
			   var selectSex = document.getElementById("selectSex");
			   selectSex.addEventListener("tap",function(){
			   	 var sexpicker = new mui.PopPicker();
				 sexpicker.setData([{
					 value:"男",
					 text:"男"
					},
					{
					value:"女",
					text:"女"}
				]);
				sexpicker.show(function(item){
					console.log(item[0].value);
					txt_sex.value = item[0].value;
				});  
			   },false);
			})
			function refreshUserInfo(){
				var userinfo = app.getRealInfoGlobal();
				var name = userinfo.name;
				var sex = userinfo.sex;
				var birthday = userinfo.birthday;
				var height = userinfo.height;
				var beginweight = userinfo.beginweight;
				var goalweight = userinfo.goalweight;
				var nowweight = userinfo.nowweight;
				var txt_name = document.getElementById("txt_name");
				var txt_sex = document.getElementById("txt_sex");
				var txt_birthday = document.getElementById("txt_birthday");
				var txt_height = document.getElementById("txt_height");
				var txt_beginweight = document.getElementById("txt_beginweight");
				var txt_goalweight = document.getElementById("txt_goalweight");
				var txt_nowweight = document.getElementById("txt_nowweight");
				txt_sex.value = sex;txt_name.value = name;
				txt_birthday.value = birthday;txt_height.value = height;
				txt_beginweight.value = beginweight;txt_goalweight.value = goalweight;
				txt_nowweight.value = nowweight;
				
			}
		</script>
	</body>

</html>
